package com.hup.winHolderService.service.mouseMove;

import com.hup.utils.commons.hardware.HRobotJni;
import com.hup.utils.commons.hardware.MouseUtil;
import com.hup.winHolderService.model.action.MouseActionReq;

import java.awt.Point;

/**
 * 算法2
 * 问题:
 * .移动时, 光标[比算法1]"更卡"??
 * .不能同时兼顾长短距离的移动
 *
 * @author hugan
 * @date 2023/10/13
 */
public class MouseMoveHandler2 implements MouseMoveHandler {

    private int lastX, lastY;

    @Override
    public void onMoveStart(MouseActionReq req) {
        lastX = req.getX();
        lastY = req.getY();
    }

    @Override
    public void onMove(MouseActionReq req) {
        Point location = MouseUtil.getLocation();
        HRobotJni.mouseMove((int) (location.x + (req.getX() - lastX) * req.getRatio()),
                (int) (location.y + (req.getY() - lastY) * req.getRatio()));
        lastX = req.getX();
        lastY = req.getY();
    }

}
